/**
 * 
 */
package cn.com.winning.ecare.utils;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import android.os.Looper;
import cn.com.winning.ecare.model.UserRecords;

/**
 * @author Administrator
 */
public class UserRecord
{

	private UserRecords userRecords;

	private static UserRecord singleton;

	private UserRecord(UserRecords userRecords)
	{
		this.userRecords = userRecords;
	}

	public static UserRecord getInstance(UserRecords userRecords)
	{
		if (singleton == null)
		{
			singleton = new UserRecord(userRecords);
		}
		return singleton;
	}

	public void init()
	{
		new Thread(new BroadCast()).start();
	}

	private class BroadCast implements Runnable
	{

		/*
		 * (non-Javadoc)
		 * 
		 * @see java.lang.Runnable#run()
		 */
		@Override
		public void run()
		{
				Looper.prepare();
				broadCast();
				Looper.loop();
		}

	}

	private void broadCast()
	{
		List<NameValuePair> ls = new ArrayList<NameValuePair>();
		String userinfo = JsonBuilder.getInstance().toJson(userRecords);
		ls.add(new BasicNameValuePair("userrecords", userinfo));
		JSONObject json = HTTPGetTool.getTool().post(URLUtils.HOSTMAIN + URLUtils.LOGINUSERRECORD, ls);
	}

	public UserRecords getUserRecords()
	{
		return userRecords;
	}

	public void setUserRecords(UserRecords userRecords)
	{
		this.userRecords = userRecords;
	}


}
